<?php

/**
 * Plugin Name:       Accordion - 手风琴区块
 * Description:       添加手风琴区块功能
 * Requires at least: 6.1
 * Requires PHP:      7.0
 * Version:           0.1.0
 * Author:            The WordPress Contributors
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       accordion
 *
 * @package           create-block
 */

/**
 * Registers the block using the metadata loaded from the `block.json` file.
 * Behind the scenes, it registers also all assets so they can be enqueued
 * through the block editor in the corresponding context.
 *
 * @see https://developer.wordpress.org/reference/functions/register_block_type/
 */
function create_block_accordion_block_init()
{
    register_block_type(__DIR__ . '/build');
}
add_action('init', 'create_block_accordion_block_init');

//添加区块分类

function filter_block_categories_when_post_provided_npcink($block_categories, $editor_context)
{
    //图标
   
    if (!empty($editor_context->post)) {
        // 使用 array_column 函数提取分类的 slug 属性
        $existing_slugs = array_column($block_categories, 'slug');

        // 如果 'custom-category' 分类不存在，则添加并移到第一位
        if (!in_array('npcink-category', $existing_slugs, true)) {
            $custom_category = array(
                'slug'  => 'npcink-category',
                'title' => __('Npcink', 'npcink-category'),
                'icon'  =>  'editor-removeformatting',
            );
            array_unshift($block_categories, $custom_category);
        }
    }

    return $block_categories;
}

add_filter('block_categories_all', 'filter_block_categories_when_post_provided_npcink', 10, 2);
